Method for programmatic editing of configuration files

ABSTRACT

A file format corresponding to each configuration file is identified. Each configuration file is parsed into a single tree structure with the corresponding file format. The single tree structure is modified with an Application Program Interface (API). The configuration file is bidirectionally updated to reflect the modified single tree structure while preserving the file format of each configuration file. The file format includes instructions on how each entry in each configuration file is to be mapped into the single tree structure.

RELATED APPLICATIONS

The present application is related to co-pending patent application Ser.No. ______, entitled “Method for programmatic editing of text files”,filed on Feb. 26, 2009.

TECHNICAL FIELD

Embodiments of the present invention relate to computing systems, andmore particularly, to changing configuration files in Unix-basedmachines.

BACKGROUND

Unix-based configuration management lacks a local configuration API.Without such an API, programmatic configuration changes and higher-levelconfiguration services such as configuration daemons and remoteconfiguration API's are based on ad-hoc mechanisms that are fragile andhard to develop and maintain. At the same time, the main culprit forthis situation, that configuration data is generally stored inconfiguration files in a wide variety of formats, is both an importantpart of the Linux culture and valuable when humans need to makeconfiguration changes manually.

Changing configuration files on Unix-style machines fromscripts/programs is extremely hard and error prone because the formatsand conventions of those files varies widely from file to file.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention is illustrated by way of examples and not by wayof limitation, in the figures of the accompanying drawings and in which:

FIG. 1 is a block diagram illustrating one embodiment of an overallarchitecture for manipulating a configuration file through an API file.

FIG. 2 is a block diagram illustrating one embodiment of a node of atree.

FIG. 3 is a block diagram illustrating one embodiment of a tree.

FIG. 4 is a block diagram illustrating one embodiment of an apparatusfor editing configuration files.

FIG. 5 is a block diagram illustrating one embodiment of theconfiguration editing tool.

FIG. 6 is a flow diagram illustrating one embodiment of a method forediting configuration files.

FIG. 7 is a block diagram illustrating an example of a computer system.

DETAILED DESCRIPTION

Described herein is a method and apparatus for editing configurationfiles with different formats. In one embodiment, a file formatcorresponding to each configuration file is identified. Eachconfiguration file is parsed into a single tree structure with thecorresponding file format. The tree structure is modified with anApplication Program Interface (API). Each configuration file is updatedto reflect the modified tree structure while preserving the file formatof each configuration file. The file format includes instructions on howeach entry in each configuration file is to be mapped into the treestructure.

FIG. 1 is a block diagram illustrating one embodiment of an overallarchitecture for manipulating a configuration file through an API file.A configuration editing tool 106 parses configuration files 108 in theirnative formats and transforms them into a single tree 104. Eachconfiguration file 116, 118, and 120 may each have a different formatcorresponding to a particular lens or editing tool 106. For example, theformat of configuration file 116 corresponds to lens 110. The format ofconfiguration file 118 corresponds to lens 112. The format ofconfiguration file 120 corresponds to lens 114. A local configurationAPI 102 manipulates tree 104 and saves it back into native configurationfiles 108.

The local configuration API 102 presents configuration data as a singletree. The tree is backed directly by the various configuration fileswithout any additonal lookaside information. Therefore no changes to theprograms using that data are required. The program can be usedside-by-side with any other mechanism to change that data. Theconfiguration editing tool 106 takes great care to preserve comments andformatting details, so that changes to tree 104 change the underlyingconfiguration file in ways that are intuitive, easy to predict, and asclose as possible to how a human would make the same change manually.

The transformation from configuration files 108 into tree 104, and fromthe updated tree 104 back to an updated file 108 is controlled by adescription of each configuration file. The description is itself aconfiguration file and consists of a specification of the file format,expressed through regular expressions, and instructions on how eachentry in the file is to be mapped into the tree 104.

The file format description consists for the most part of a lens 106that transforms text into tree and tree into text at the same time,relieving the developer of keeping those two transformationssynchronized. Lenses are statically type-checked so that a large numberof problems can be diagnosed based on the lens only, preventing wholeclasses of runtime errors when the lens is applied to actual text.

Descriptions for new file formats can be added in a modular fashion;this makes it possible to distribute file format descriptions togetherwith the configuration file, rather than the configuration editing tool.

In one embodiment, API 102 includes a simple command line tool that canbe used for simple changes from shell scripts, as well as a public Clibrary API, and bindings for Perl, Python,Ruby, Java, and OCaml. Inthat embodiment, file format descriptions for many common Linuxconfiguration files are also provided.

FIG. 2 is a block diagram illustrating one embodiment of a node of atree created by the editing tool. Each node in the tree consists ofthree pieces of data: a label 204, a value 206, and a list of siblingnodes 202 and child nodes 208. The label and value are both strings. Thelabel is used in the path to the node and child nodes, much as filenames are used in the paths to files in a file system, with theexception that multiple siblings can have the same label.

The public API allows traversing the tree with Xpath-like expressions,and therefore also provides a convenient way to query existingconfiguration files.

FIG. 3 is a block diagram illustrating one embodiment of a tree with thenodes of FIG. 2. A node 302 has a child node 304. Child node 304 hassibling nodes 306, 308, 310. A node can have multiple children with thesame label. A node can have any number of children called foo. In paths,a specific child can be picked out with foo[N] where N is a positivenumber the first child with label foo is picked with foo[1], and thelast can be picked with foo[last( )]. Just foo in a path picks all thechildren with that label.

FIG. 4 is a block diagram illustrating one embodiment of an apparatus400 for editing configuration files. Apparatus 400 includes applications402, configuration editing tool 404, configuration files 406, API 408,and operating system 410. Configuration editing tool 404 allows a userto edit or modify configuration files 406. Configuration editing tool404 is described in more detail with respect to FIG. 5.

FIG. 5 is a block diagram illustrating one embodiment of theconfiguration editing tool 404. Configuration editing tool 404 includesAPI 502, lenses 504 (506, 508, 510) and a tree 512. Lenses are thebuilding blocks of the file to and from tree transformation. Theycombine parsing a configuration file and building the tree with “get”transformation, and turning the tree back into an updated configurationfile with the “put” transformation.

A bidirectional language is one where the program expresses atransformation from input to output, and from (possibly modified) outputback to the corresponding input. They are called bidirectional ratherthan bijective because there are generally many inputs for the sameoutput and vice versa. In the present case, many input files (e.g.,/etc/hosts with varying amounts of whitespace between fields) map to thesame tree, and there are many ways to map the same tree back to a file.

Lenses 504 perform the parsing between the tree and the configurationfile. For example, the parsing is performed with the lenses matchingregular expressions. Different lenses do different things with thestrings that match (create a new tree node with a certain label, store avalue in a tree node, combine tree nodes into a larger tree). Writingthe regular expressions is the main task when describing a file format.

FIG. 6 is a flow diagram illustrating one embodiment of a method forediting configuration files. At 602, a file format corresponding to eachconfiguration file is identified. At 604, all configuration files areparsed into a single tree structure with the corresponding file format.At 606, the single tree structure is modified using an ApplicationProgram Interface (API). At 60S the configuration file isbidirectionally updated to reflect the modified tree structure whilepreserving the file format of the configuration files.

In one embodiment, the file format includes instructions on how eachentry in the configuration file is to be mapped into the tree structure.The API includes a command line tool to manipulate the configurationfile from a shell.

In another embodiment, mapping includes parsing the configuration filewith a get function to produce the tree structure, and transforming thetree structure back into the configuration file with a put and createfunction.

FIG. 7 illustrates a diagrammatic representation of a machine in theexemplary form of a computer system 700 within which a set ofinstructions, for causing the machine to perform any one or more of themethodologies discussed herein, may be executed. In alternativeembodiments, the machine may be connected (e.g., networked) to othermachines in a LAN, an intranet, an extranet, or the Internet. Themachine may operate in the capacity of a server or a client machine inclient-server network environment, or as a peer machine in apeer-to-peer (or distributed) network environment. The machine may be apersonal computer (PC), a tablet PC, a set-top box (STB), a PersonalDigital Assistant (PDA), a cellular telephone, a web appliance, aserver, a network router, switch or bridge, or any machine capable ofexecuting a set of instructions (sequential or otherwise) that specifyactions to be taken by that machine. Further, while only a singlemachine is illustrated, the term “machine” shall also be taken toinclude any collection of machines that individually or jointly executea set (or multiple sets) of instructions to perform any one or more ofthe methodologies discussed herein.

The exemplary computer system 700 includes a processing device 702, amain memory 704 (e.g., read-only memory (ROM), flash memory, dynamicrandom access memory (DRAM) such as synchronous DRAM (SDRAM), a staticmemory 706 (e.g., flash memory, static random access memory (SRAM),etc.), and a data storage device 718, which communicate with each othervia a bus 730.

Processing device 702 represents one or more general-purpose processingdevices such as a microprocessor, central processing unit, or the like.More particularly, the processing device may be complex instruction setcomputing (CISC) microprocessor, reduced instruction set computing(RISC) microprocessor, very long instruction word (VLIW) microprocessor,or processor implementing other instruction sets, or processorsimplementing a combination of instruction sets. Processing device 702may also be one or more special-purpose processing devices such as anapplication specific integrated circuit (ASIC), a field programmablegate array (EPGA), a digital signal processor (DSP), network processor,or the like. The processing device 702 is configured to execute modules726 (previously described with respect to FIG. 1) for performing theoperations and steps discussed herein with. In one embodiment, themodules may be include hardware or software or a combination of both.

The computer system 700 may further include a network interface device708. The computer system 700 also may include a video display unit 710(e.g., a liquid crystal display (LCD) or a cathode ray tube (CRT)), analphanumeric input device 712 (e.g., a keyboard), a cursor controldevice 714 (e.g., a mouse), and a signal generation device 716 (e.g., aspeaker).

The data storage device 718 may include a computer-accessible storagemedium 730 on which is stored one or more sets of instructions (e.g.,software 722) embodying any one or more of the methodologies orfunctions described herein. The software 722 may also reside, completelyor at least partially, within the main memory 704 and/or within theprocessing device 702 during execution thereof by the computer system700, the main memory 704 and the processing device 702 also constitutingcomputer-accessible storage media. The software 722 may further betransmitted or received over a network 720 via the network interfacedevice 708.

The computer-accessible storage medium 730 may also be used to store theconfiguration editing tool 724 as presently described. The configurationediting tool 724 may also be stored in other sections of computer system700, such as static memory 706.

While the computer-accessible storage medium 730 is shown in anexemplary embodiment to be a single medium, the term“computer-accessible storage medium” should be taken to include a singlemedium or multiple media (e.g., a centralized or distributed database,and/or associated caches and servers) that store the one or more sets ofinstructions. The term “computer-accessible storage medium” shall alsobe taken to include any medium that is capable of storing, encoding orcarrying a set of instructions for execution by the machine and thatcause the machine to perform any one or more of the methodologies of thepresent invention. The term “computer-accessible storage medium” shallaccordingly be taken to include, but not be limited to, solid-statememories, optical and magnetic media.

In the above description, numerous details are set forth. It will beapparent, however, to one skilled in the art, that the present inventionmay be practiced without these specific details. In some instances,well-known structures and devices are shown in block diagram form,rather than in detail, in order to avoid obscuring the presentinvention.

Some portions of the detailed descriptions above are presented in termsof algorithms and symbolic representations of operations on data bitswithin a computer memory. These algorithmic descriptions andrepresentations are the means used by those skilled in the dataprocessing arts to most effectively convey the substance of their workto others skilled in the art. An algorithm is here, and generally,conceived to be a self-consistent sequence of steps leading to a desiredresult. The steps are those requiring physical manipulations of physicalquantities. Usually, though not necessarily, these quantities take theform of electrical or magnetic signals capable of being stored,transferred, combined, compared, and otherwise manipulated. It hasproven convenient at times, principally for reasons of common usage, torefer to these signals as bits, values, elements, symbols, characters,terms, numbers, or the like.

It should be borne in mind, however, that all of these and similar termsare to be associated with the appropriate physical quantities and aremerely convenient labels applied to these quantities. Unlessspecifically stated otherwise as apparent from the following discussion,it is appreciated that throughout the description, discussions utilizingterms such as “processing” or “computing” or “calculating” or“determining” or “displaying” or the like, refer to the action andprocesses of a computer system, or similar electronic computing device,that manipulates and transforms data represented as physical(electronic) quantities within the computer system's registers andmemories into other data similarly represented as physical quantitieswithin the computer system memories or registers or other suchinformation storage, transmission or display devices.

The present invention also relates to apparatus for performing theoperations herein. This apparatus may be specially constructed for therequired purposes, or it may comprise a general purpose computerselectively activated or reconfigured by a computer program stored inthe computer. Such a computer program may be stored in a computerreadable storage medium, such as, but is not limited to, any type ofdisk including floppy disks, optical disks, CD-ROMs, andmagnetic-optical disks, read-only memories (ROMs), random accessmemories (RAMs), EPROMs, EEPROMs, magnetic or optical cards, or any typeof media suitable for storing electronic instructions, and each coupledto a computer system bus.

The algorithms and displays presented herein are not inherently relatedto any particular computer or other apparatus. Various general purposesystems may be used with programs in accordance with the teachingsherein, or it may prove convenient to construct more specializedapparatus to perform the required method steps. The required structurefor a variety of these systems will appear from the description below.In addition, the present invention is not described with reference toany particular programming language. It will be appreciated that avariety of programming languages may be used to implement the teachingsof the invention as described herein.

It is to be understood that the above description is intended to beillustrative, and not restrictive. Many other embodiments will beapparent to those of skill in the art upon reading and understanding theabove description. The scope of the invention should, therefore, bedetermined with reference to the appended claims, along with the fullscope of equivalents to which such claims are entitled.

1. A computer-implemented method comprising: identifying a correspondingfile format for each configuration file with an editing tool module;parsing each configuration file into a single tree structure with thecorresponding file format; modifying the single tree structure with anApplication Program Interface (API) module; and bidirectionally updatingeach configuration file to reflect the modified single tree structurewhile preserving the file format of each configuration file.
 2. Thecomputer-implemented method of claim 1 wherein the file format includesinstructions on how each entry in each configuration file is to bemapped into the single tree structure.
 3. The computer-implementedmethod of claim 1 wherein the API module includes a command line tool tomanipulate each configuration file from a shell.
 4. Thecomputer-implemented method of claim 1 further comprising: storing alibrary of file formats.
 5. The computer-implemented method of claim 1wherein a node of the single tree structure includes a sibling field, alabel field, a value field, and a child field. 6 Thecomputer-implemented method of claim 1 further comprising: synchronouslymapping between each configuration file and the single tree structure.7. The computer-implemented method of claim 6 wherein mapping includesparsing each configuration file with a get function to produce thesingle tree structure, and transforming the single tree structure backinto each corresponding configuration file with a put and createfunction.
 8. A computer-readable storage medium, having instructionsstored therein, which when executed, cause a computer system to performa method comprising: identifying a corresponding file format for eachconfiguration file; parsing each configuration file into a single treestructure with the corresponding file format; modifying the single treestructure with an Application Program Interface (API) module; andbidirectionally updating each configuration file to reflect the modifiedsingle tree structure while preserving the file format of eachconfiguration file.
 9. The computer-readable storage medium of claim 8wherein the file format includes instructions on how each entry in eachconfiguration file is to be mapped into the single tree structure. 10.The computer-readable storage medium of claim 8 wherein the API moduleincludes a command line tool to manipulate each configuration file froma shell.
 11. The computer-readable storage medium of claim 8 wherein themethod further comprises: storing a library of file formats.
 12. Thecomputer-readable storage medium of claim 8 wherein a node of the singletree structure includes a sibling field, a label field, a value field,and a child field.
 13. The computer-readable storage medium of claim 8wherein the method further comprises: synchronously mapping between eachconfiguration file and the single tree structure.
 14. Thecomputer-readable storage medium of claim 13 wherein mapping includesparsing each configuration file with a get function to produce thesingle tree structure, and transforming the single tree structure backinto each corresponding configuration file with a put and createfunction.
 15. A system comprising: a storage for storing a plurality ofconfiguration files; and an editing tool coupled to the storage, theediting tool comprising an API module configured to synchronously mapbetween each configuration file and a single tree structure, andbidirectionally update the configuration file based on manipulation tothe single tree structure while preserving a file format of eachconfiguration file.
 16. The system of claim 15 wherein the editing toolis configured to identify a file format corresponding to eachconfiguration file, to parse each configuration file into the singletree structure with the corresponding file format, to modify the singletree structure with the API module, and to update each configurationfile to reflect the modified single tree structure.
 17. The system ofclaim 15 wherein the API module includes a command line tool tomanipulate each configuration file from a shell.
 18. The system of claim15 wherein the storage further includes a library of file formats, eachfile format includes instructions on how each entry in eachconfiguration file is to be mapped into the single tree structure. 19.The system of claim 15 wherein a node of the single tree structureincludes a sibling field, a label field, a value field, and a childfield.
 20. The system of claim 15 wherein the editing tool includes aget function configured to parse each configuration file to produce thesingle tree structure, and a put and create function configured totransform the single tree structure back into each correspondingconfiguration file.